import matplotlib.pyplot as plt
import time
import re

log_path = "train_2021_04_01_17_49_16.log"

train_loss = []
test_loss = []
train_acc = []
test_acc = []

def read_log():
    file = open(log_path,"r")
    for line in file:
        if re.search("INFO",line):
            # print(line[-25:-19]+" "+line[-7:-1]+" "+line[83:92]+" "+line[105:114])
            train_acc.append(line[-25:-19])
            test_acc.append(line[-7:-1])
            train_loss.append(line[85:101])
            test_loss.append(line[115:123])
    file.close()
    return

def figue():
    plt.plot(range(0,len(train_acc)),list(map(float, train_acc)),label="train_acc",color="red",linestyle="-.")
    plt.plot(range(0,len(test_acc)),list(map(float, test_acc)),label="test_acc",color="blue",linestyle="--")
    plt.title("The variation curve of accuracy")
    plt.xlabel("batch_time")
    plt.ylabel("accuracy")
    plt.show()

    plt.plot(range(0, len(train_loss)), list(map(float, train_loss)), label="train_loss", color="green", linestyle="-.")
    # plt.plot(range(0, len(test_loss)), list(map(float, test_loss)), label="test_loss", color="green", linestyle="--")
    plt.title("The variation curve of loss")
    plt.xlabel("batch_time")
    plt.ylabel("loss")
    plt.show()

if __name__ == "__main__":
    read_log()
    figue()